 <template>
  <el-container>
    <el-main>
      <el-row class="form_contianer">     
        <el-col :span='24'>
          <strong>用户：{{userName}}</strong>
        </el-col>   
      </el-row>
      <el-row class="form_contianer">     
        <el-col :span='24'>
          <el-form :model="formData" ref="formData">
            <el-form-item label="类型">
              <el-select placeholder="增加" v-model="formData.orderCode">
                <el-option
                  v-for="item in options"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
            <!-- <el-form-item prop="userId" class="adminAdjust" label="增加金额(单位:元)" :visible.sync='false'>
                <el-input placeholder="id" :value="userId"></el-input>
            </el-form-item> -->
            <el-form-item class="adminAdjust" label="金额(单位:元)">
                <el-input v-model="formData.orderAmount" placeholder="金额" clearable ></el-input>
            </el-form-item>
            <el-form-item class="adminAdjust" label="备注">
                <el-input
                  type="textarea"
                  :rows="2"
                  placeholder="请输入内容(可选)"
                  v-model="formData.orderMemo">
                </el-input>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" @click="adminAdjustTo()" class="submit_btn">确定</el-button>
            </el-form-item>
          </el-form>
        </el-col>   
      </el-row>

      <!-- <el-row class="form_contianer2">
        <el-col :span='24'>
          <el-form :model="formDataOut" ref="formDataOut" :inline="true">
              <el-form-item prop="orderAmount" class="adminAdjust" label="减少金额(单位:元)">
                  <el-input v-model="formDataOut.orderAmount" placeholder="金额" clearable></el-input>
              </el-form-item>
              <el-form-item>
                  <el-button type="primary" @click="adminAdjustToOut(formDataOut)" class="submit_btn">减少金币</el-button>
              </el-form-item>
          </el-form>
        </el-col>   
      </el-row> -->
    </el-main>
  </el-container>
</template>

<script>
  import {adminGetUserInfo, adminAdjust, adminAdjustConfirm} from '@/api/admin'

  export default {
    props: ['userName', 'tel', 'userId'],
    data () {
      return {
        options: [
          {
            value: '200111',
            label: '增加金额'
          },
          {
            value: '200112',
            label: '减少金额'
          }
        ],
        formData: {
          orderCode: '200111', 
          orderAmount: 0, 
          userId: 0,
          orderMemo: ''
        },
        // formDataOut: {
        //   orderCode: '200112', orderAmount: 0, userId: 0
        // },
        adjustConfirmDto: {
          id: 1,
          status: 'ENABLE'
        }
      }
    },
    mounted () {
      this.initData()
    },
    methods: {
      initData () {
        this.formData.userId = this.userId
      },

      async adminAdjustTo (formData) {
        let formDataCopy = Object.assign({}, this.formData)
        // formDataCopy.userId = this.userId
        formDataCopy.orderAmount = Math.abs((this.formData.orderAmount * 100 ).toFixed(0))
        
        let result = await adminAdjust(formDataCopy)
        if (result.status === 200 && result.data.code === 200) {
          let data = result.data
          this.adjustConfirmDto.id = data.data.id
          
          this.adminAdjustConfirmClick(formDataCopy)
        } else {
        }
      },
      // async adminAdjustToOut (formDataOut) {
      //   let formDataOutCopy = Object.assign({}, this.formDataOut)
      //   formDataOutCopy.userId = this.userId
      //   formDataOutCopy.orderAmount = Math.abs((this.formDataOut.orderAmount *100 ).toFixed(0))

      // //   this.formDataOut.userId = this.userInfo.userId
      // //   this.formDataOut.orderAmount = this.formDataOut.orderAmount *100 
      //   let result = await adminAdjust(formDataOutCopy)
      //   if (result.status === 200 && result.data.code === 200) {
      //     let data = result.data
  
      //     this.adjustConfirmDto.id = data.data.id
      //     this.adminAdjustConfirmClick()
      //   } else {
  
      //   }
      // },

      async adminAdjustConfirmClick (formDataCopy) {
        const loading = this.$loading({
          lock: true,
          text: 'Loading',
          spinner: 'el-icon-loading',
          background: 'rgba(0, 0, 0, 0.7)'
        });
       
        let result = await adminAdjustConfirm(this.adjustConfirmDto)
        if (result.status === 200 && result.data.code === 200) {
          this.$message({
            type: 'success',
            message: '调账成功'
          })
          this.$emit('balance-update')
        } else {
  
        }
        loading.close();

      },
      // 直接用了以下全流程的方法
      // async adminAdjustToInWithUserInfo (formData) {
      //   let result = await adminGetUserInfo(this.accountInfo)
      //   if (result.status === 200 && result.data.code === 200) {
      //     let data = result.data
      //     this.userInfo.userId = data.data[0].id
      //     this.adminAdjustToIN(this.formData)
          
      //   } else {
      //     this.$message({
      //       type: 'error',
      //       message: '未匹配到用户'
      //     })
      //   }
      // },
      // async adminAdjustToOutWithUserInfo (formDataOut) {
      //   let result = await adminGetUserInfo(this.accountInfo)
      //   if (result.status === 200 && result.data.code === 200) {
      //     let data = result.data
      //     this.userInfo.userId = data.data[0].id
      //     this.adminAdjustToOut(this.formDataOut)
      //   } else {
      //     this.$message({
      //       type: 'error',
      //       message: '未匹配到用户'
      //     })
      //   }
      // }

    }
  }
</script>

<style lang="less" scoped>
    @import '../../style/mixin';
    .label-title{
        font-weight: bold;
        font-size: 24px;
        color: #ff633b;
        margin: 30px;
    }
    .manage_tip {
      margin-bottom: 10px;
    }
    .introduct{
        width: 900px;
        text-align: center;
        margin: auto;
    }
    .tip {
        font-size: 12px;
    }
    .tip strong {
        color: red;
        font-weight: bold;
    }
    strong {
      font-size: 16px;
    }
    .el-row {
      margin-bottom: 10px;
    }
    // .el-button {
    //   width: 200px;
    //   margin: auto;
    //   display: block;
    // }
    .el-table .info-row {
        background: #c9e5f5;
    }

    .el-table .positive-row {
        background: #e2f0e4;
    }

    
</style>

 